﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.RoleCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.RoleHandler
{
    public class GetFanTianCommandHandler : IRequestHandler<GetFanTianCommand, APIResult<List<RoleMenu>>>
    {
        private readonly IBaseRepository<RoleMenu> roleMenuRepos;

        public GetFanTianCommandHandler(IBaseRepository<RoleMenu> roleMenuRepos)
        {
            this.roleMenuRepos = roleMenuRepos;
        }

        public async Task<APIResult<List<RoleMenu>>> Handle(GetFanTianCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleMenu>> result = new APIResult<List<RoleMenu>>();

            var list = roleMenuRepos.GetAll().Where(x => x.RoleId == request.RoleId);
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";
            result.Data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
